package com.cg.pm;

import com.aliyun.oss.OSSClient;

import java.io.InputStream;

/**
 * Created by Swinglife on 16/8/1.
 */
public class OSSUtil {

    public final static String IMAGE_URL = "http://jwbucket.oss-cn-shanghai.aliyuncs.com/";

    public final static String ACCESS_KEY_ID = "LTAIbM4qrWdSwCVw";
    public final static String ACCESS_KEY_SECRET = "GpUH1RaNphDi6U2vMqioHnHzDQHmrv";
    public final static String ENDPOINT = "http://oss-cn-shanghai.aliyuncs.com";

    public static void uploadFileToOss(String fileName, InputStream inputStream){
        // 创建OSSClient实例
        OSSClient ossClient = new OSSClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
        ossClient.putObject("jwbucket", fileName, inputStream);
        ossClient.shutdown();
    }

    public static void deleteFileToOss(String fileName){
        // 创建OSSClient实例
        OSSClient ossClient = new OSSClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
        ossClient.deleteObject("jwbucket", fileName);
        ossClient.shutdown();
    }
}
